#ifndef ___B_RING_BUFFER_H___
#define ___B_RING_BUFFER_H___

#include <stdlib.h>
#include <stdio.h>

typedef struct {
    pthread_mutex_t lock;
    pthread_cond_t not_full;
    pthread_cond_t not_empty;
    unsigned char *buffer;
    size_t total_size;
    size_t head;
    size_t tail;
    size_t free_size;
} ringbuffer_t;

ringbuffer_t *ringbuffer_init(size_t size);

void ringbuffer_free(ringbuffer_t *rb);

size_t ringbuffer_write(ringbuffer_t *rb, const void *data, size_t len);

size_t ringbuffer_read(ringbuffer_t *rb, void *data, size_t len);

size_t ringbuffer_available_to_read(ringbuffer_t *rb);

size_t ringbuffer_available_to_write(ringbuffer_t *rb);

#endif